#!/bin/sh
#
# This test uses two pools, two tapes, and
#  an autochanger. Note, the Director has three Pools in its
#  conf:  Default, Full, and Inc.  Default is used in the
#  NightlySave job by default.  What is backed up is what
#  is in ${cwd}/tmp/file-list.
#
#  Note, we use the virtual disk autochanger.
#
TestName="fast-two-pool-test"
JobName=Fast-two-pool
. scripts/functions

scripts/cleanup
scripts/copy-2disk-confs
scripts/prepare-disk-changer

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
# TODO: use larger backup data set.
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
# Make a relatively large backup by using making it multiple times.
echo "${BackupDirectory}" >${tmp}/file-list
echo "${BackupDirectory}" >>${tmp}/file-list
echo "${BackupDirectory}" >>${tmp}/file-list
echo "${BackupDirectory}" >>${tmp}/file-list


start_test

# Write out bconsole commands to a file
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
@#setdebug level=150 storage=tape
label storage=tape volume=TestVolume001 slot=1 pool=Full drive=0
label storage=tape volume=TestVolume002 slot=2 pool=Default drive=0
list volumes
@# Start job with Client run before and sleep
run job=NightlySave1 level=Full pool=Default yes
run job=NightlySave1 level=Full pool=Default yes
@# wait between starting jobs
@sleep 10
@#setdebug level=100 storage=tape
run job=NightlySave1 level=Full pool=Full yes
run job=NightlySave1 level=Full pool=Full yes
status storage=tape
messages
wait
list volumes
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
list volumes
list jobs
status storage=tape
messages
setdebug level=200 storage=tape
@#setdebug level=200 client
restore where=${cwd}/tmp/susan-restores select all storage=tape done
yes
wait
messages
quit
END_OF_DATA

# exit
run_susan
check_for_zombie_jobs storage=tape
stop_susan

check_two_logs
check_restore_diff
end_test
